package com.neu.envprotection.admin.controller;

import com.neu.envprotection.admin.dto.resp.GetVerifyCodeRespDto;
import com.neu.envprotection.common.resp.PageRespDto;
import com.neu.envprotection.common.resp.RestResp;
import com.neu.envprotection.common.constant.SystemConfigConsts;
import com.neu.envprotection.admin.dao.entity.User;
import com.neu.envprotection.admin.dto.req.GetGridManReqTto;
import com.neu.envprotection.admin.dto.req.GetSupervisorReqDto;
import com.neu.envprotection.admin.dto.req.UserLoginReqDto;
import com.neu.envprotection.admin.dto.req.UserRegisterReqDto;
import com.neu.envprotection.admin.dto.resp.GetGridManRespDto;
import com.neu.envprotection.admin.dto.resp.GetSupervisorRespDto;
import com.neu.envprotection.admin.dto.resp.UserLoginRespDto;
import com.neu.envprotection.admin.service.UserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 管理员模块
 */

@RestController
@RequestMapping("/api/admin")
@RequiredArgsConstructor
@SecurityRequirement(name = SystemConfigConsts.HTTP_AUTH_HEADER_NAME)
@Tag(name = "用户管理端接口")
@Slf4j
public class UserController {
    @Autowired
    private UserService userService;

    @PostMapping("/register")
    @Operation(summary = "用户注册")
    private RestResp<Void> register(@RequestBody UserRegisterReqDto dto){
        return userService.register(dto);
    }


    @PostMapping("/login")
    @Operation(summary = "用户登录接口")
    private RestResp<UserLoginRespDto> login(@RequestBody UserLoginReqDto userLoginReqDto){

        return userService.login(userLoginReqDto);
    }

    @PostMapping("/info")
    private RestResp<User> getUserById(@RequestBody String id){
        return userService.getUserById(Integer.parseInt(id));
    }


    @PostMapping("/querySupervisor")
    @Operation(summary = "分页获得监督员")
    private RestResp<PageRespDto<GetSupervisorRespDto>> getSupervisor(@RequestBody GetSupervisorReqDto dto){
        return userService.queryPageSupervisor(dto);
    }

    @PostMapping("/queryGridMan")
    @Operation(summary = "分页查找网格员")
    private RestResp<PageRespDto<GetGridManRespDto>> getGridMan(@RequestBody GetGridManReqTto dto){
        return userService.queryGridMan(dto);
    }

    @GetMapping("/getAllGridMan")
    @Operation(summary = "获得所有网格员")
    private RestResp<List<GetGridManRespDto>> getAllGridMan(){
        return userService.getAllGridMan();
    }

    @GetMapping("/getVerifyCode")
    @Operation(summary = "获得随机验证码")
    private RestResp<GetVerifyCodeRespDto> getVerifyCode(){
        return userService.getVerifyCode();
    }

    @PostMapping("/delete/{uid}")
    @Operation(summary = "注销用户")
    private RestResp<Void> deleteUser(@PathVariable Integer uid){
        return userService.deleteUser(uid);
    }


}
